import Vue from 'vue'
import Vuex from 'vuex'
import createPersistedState from 'vuex-persistedstate'
import { getUserInfoAPI } from '@/api'
Vue.use(Vuex)

export default new Vuex.Store({
  state: {
    token: '',
    userinfo: {}
  },
  getters: {
    name: state => state.userinfo.name,
    nickname: state => state.userinfo.nickname,
    avator: state => state.userinfo.avator,
    admin_id: state => state.userinfo.admin_id,
    position: state => state.userinfo.position

  },
  mutations: {
    updateToken(state, val) {
      state.token = val
    },
    updateUserInfo(state, val) {
      state.userinfo = val
    }
  },
  actions: {
    async getuserInfoActions(store) {
      const res = await getUserInfoAPI()
      console.log(res, '****999');
      store.commit('updateUserInfo', res.data.results)
    }
  },
  modules: {
  },
  plugins: [
    createPersistedState()
  ]
})
